clear
capture log close
log using "c:\users\severinborenstein\dropbox\clean energy tax credits\stata\leasing\leasing.slf"
set more off
cd "c:\users\severinborenstein\dropbox\clean energy tax credits\stata\leasing"

clear
insheet using c:\users\severinborenstein\dropbox\solarpv\lbnldata\TTS_LBNL_public_file_27-Oct-2023_all.csv
save c:\temp\temp1, replace

tab customer_segment
keep if customer_segment=="RES"

list installation_date in 1/10

tab third_party_owned

g thirdparty=0
replace thirdparty=1 if third_party_owned==1
g owned=0
replace owned=1 if third_party_owned==0

g yr=year(date(installation_date,"DMY"))

sort yr

collapse (sum) thirdparty owned, by (yr)

g thirdpartyshr=thirdparty/(thirdparty+owned)




















************SLIGHTLY DIFFERENT VARIABLE NAMES, CAN'T APPEND************
clear
insheet using TTS_LBNL_public_file_27-Jan-2022_p1.csv
append using c:\temp\temp1

rename incentiveamount rebate
rename nameplaterating nameplate
rename firstcompleteddate completed
rename installedstatus status
rename hostcustomerphysicalzipcode zipcode
rename hostcustomersector customertype

tab status

keep if status=="Installed"

g yr=year(date(completed,"YMD"))
g mo=month(date(completed,"YMD"))
g dy=day(date(completed,"YMD"))

g PBI=0
replace PBI=1 if incentivetype=="FiveYearPBI"

replace yr=year(date(firstpbiinpaymentdate,"YMD")) if PBI==1
replace mo=month(date(firstpbiinpaymentdate,"YMD")) if PBI==1
replace dy=day(date(firstpbiinpaymentdate,"YMD")) if PBI==1


replace yr=year(date(firstincentiveclaimrequestreview,"YMD")) if yr==.
replace mo=month(date(firstincentiveclaimrequestreview,"YMD")) if mo==.
replace dy=day(date(firstincentiveclaimrequestreview,"YMD")) if dy==.

g leased=0
replace leased=1 if rdpartyowner=="yes"

keep yr mo dy rebate totalcost nameplate csirating completed status zipcode PBI leased program incentivetype customertype

replace yr=2013 if yr==2103

*FIX MISSING CSI RATINGS
g csiratio=csirating/nameplate
summ csiratio,d
g csiestim=0
replace csiestim=1 if csirating==. & nameplate~=.
replace csirating=0.822*nameplate if  csirating==. & nameplate~=.
drop csiratio

save c:\temp\temp1, replace

summ csirating rebate
summ csirating rebate if csirating<=10
summ csirating rebate if csirating>10


*MEASURE DECLINE IN COST/WATT DROPPING LEASED SYSTEMS
summ csirating totalcost if yr==2007
summ csirating totalcost if yr==2008
summ csirating totalcost if yr==2009
summ csirating totalcost if yr==2010
summ csirating totalcost if yr==2011
summ csirating totalcost if yr==2012
summ csirating totalcost if yr==2013
summ csirating totalcost if yr==2007 & leased==0
summ csirating totalcost if yr==2008 & leased==0
summ csirating totalcost if yr==2009 & leased==0
summ csirating totalcost if yr==2010 & leased==0
summ csirating totalcost if yr==2011 & leased==0
summ csirating totalcost if yr==2012 & leased==0
summ csirating totalcost if yr==2013 & leased==0

drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt

*MEASURE DECLINE IN COST/WATT FOR DIFFERENT SIZED SYSTEMS DROPPING LEASED SYSTEMS
clear
u c:\temp\temp1
drop if csirating>3
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating<=3 | csirating>7
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating<=7 | csirating>10
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating<=10
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating<=100
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating >10
summ
drop if leased~=0
sort yr
collapse (sum) csirating totalcost, by(yr)
g costperwatt=totalcost/csirating
list yr costperwatt, clean

clear
u c:\temp\temp1
drop if csirating >10
summ
sort yr
collapse (sum) csirating (mean) leased, by(yr)
list yr leased, clean
